package services.bkgl;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import com.Const;
import com.PublicSystem;
import com.util.Util;
/**
 * 办卡管理Service
 * @author Administrator
 *
 */
public class BkglServices {
	PublicSystem sys = PublicSystem.getInstance();
	/**
	 * 银行下拉框选项
	 * @param sj
	 * @return
	 * @throws Exception
	 */
	public List getYinhang(String sj) throws Exception {
		String sql = "select aaa103,aaa102 from v_ic_az11 where aaa100=?";
		List data = sys.query(sql, new Object[] {sj}, true);
		return data;
	}
	/**
	 * 补卡类型下拉框选项
	 * @param sj
	 * @return
	 * @throws Exception
	 */
	public List getBKLX(String sj) throws Exception {
		String sql = "select aaa103,aaa102 from v_ic_az11 where aaa100=? and aaa102='9'";
		List data = sys.query(sql, new Object[] {sj}, true);
		return data;
	}
	/**
	 * 补卡类型下拉框选项
	 * @param sj
	 * @return
	 * @throws Exception
	 */
	public List getBKLX2(String sj) throws Exception {
		String sql = "select aaa103,aaa102 from v_ic_az11 where aaa100=? and caz011 is null ";
		List data = sys.query(sql, new Object[] {sj}, true);
		return data;
	}
	/**
	 * 补卡类型下拉框选项
	 * @param sj
	 * @return
	 * @throws Exception
	 */
	public List getBKLX3(String sj) throws Exception {
		String sql = "select aaa103,aaa102 from v_ic_az11 where aaa100=? and caz011='00' and aaa102 <>'9'";
		List data = sys.query(sql, new Object[] {sj}, true);
		return data;
	}
	/**
	 * 查询单位登记信息
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public HashMap getUnitData(HashMap obj,String id) throws Exception {
		HashMap map = new HashMap();
		String ss = sys.callDBFuncProce("ic_kgl.chk_bkdj", "function", obj).toString();
		String sql1 = "select aac100 from az02 where AAC001='" + id +"'";  
		String path = Const.server_path + "/Picture/";
		String name = id + "." + "JPG";
		String file = path + name;
		File files = new File(path);
		if(!files.exists()) {
			files.mkdirs();
		}	
		boolean flag = sys.SelResultBlob(sql1, file);
		String[] msg = ss.split("&");
		if(!msg[0].equals("0")) {
			if(msg[0].contains(":")) {			
				String aa[] = msg[0].split(":");
				msg[0] = aa[1];
			}
			map.put("msg", msg[0]);
			return  map;
		}				
		String str1 = sys.SelResultStr("select chr(1) from dual");
	    String str2 = sys.SelResultStr("select chr(2) from dual");
	    String str = ss.replaceAll("&", str1);
		String sss[] = str.split(str1);
		for (int i = 1; i < sss.length; i++) {						
			String aa[] = sss[i].split(str2);				
			if(aa.length == 1) {
			    map.put(aa[0], null);
			} else {
				if(aa[0].equals("aac003")) {
					String xm = aa[1];
					String aaz742 = Util.getPingYin(xm);
					map.put("aaz742", aaz742);
				}
				map.put(aa[0], aa[1]);
			}		
		}	
		return  map;
	}
	/**
	 * 查询单位登记信息
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public HashMap getUnitData2(HashMap obj, String id) throws Exception {
		String ss = sys.callDBFuncProce("ic_kgl.chk_bkdjx", "function", obj).toString();
		HashMap map = new HashMap();
		String sql1 = "select aac100 from az02 where AAC001='" + id +"'";  
		String path = Const.server_path + "/Picture/";
		String name = id + "." + "JPG";
		String file = path + name;
		File files = new File(path);
		if(!files.exists()) {
			files.mkdirs();
		}	
		boolean flag = sys.SelResultBlob(sql1, file);
		String[] msg = ss.split("&");
		if(!msg[0].equals("0")) {
			if(msg[0].contains(":")) {			
				String aa[] = msg[0].split(":");
				msg[0] = aa[1];
			}
			map.put("msg", msg[0]);
			return  map;
		}		
		String str1 = sys.SelResultStr("select chr(1) from dual");
	    String str2 = sys.SelResultStr("select chr(2) from dual");
	    String str = ss.replaceAll("&", str1);
		String sss[] = str.split(str1);
		for (int i = 1; i < sss.length; i++) {						
			String aa[] = sss[i].split(str2);
			if(aa.length == 1) {
			    map.put(aa[0], null);
			} else {
				if(aa[0].equals("aac003")) {
					String xm = aa[1];
					String aaz742 = Util.getPingYin(xm);
					map.put("aaz742", aaz742);
				}
				map.put(aa[0], aa[1]);
			}			
		}	
		return  map;
	}
	/**
	 * 下拉框选项
	 * @param lx
	 * @return
	 * @throws Exception
	 */
	public List getSelect(String lx) throws Exception {
		String sql = "select aaa103,aaa102 FROM aa10 where aaa100=?";
		List data = sys.query(sql, new Object[] {lx}, true);
		return data;
	}
	/**
	 * 区划下拉框选项下拉框选项
	 * @param lx
	 * @return
	 * @throws Exception
	 */
	public List getSelectqh() throws Exception {
		String sql = "select bm,mch from v_ic_qmb ";
		List data = sys.query(sql, new Object[] {}, true);			
		return data;
	}
	/**
	 * 街道下拉框选项下拉框选项
	 * @param lx
	 * @return
	 * @throws Exception
	 */
	public List getSelectjd(String lx) throws Exception {
		String sql = "select bm,mch from v_ic_jdb where bm like '%'||?||'%' ";
		List data = sys.query(sql, new Object[] {lx}, true);			
		return data;
	}
	/**
	 * 社区下拉框选项下拉框选项
	 * @param lx
	 * @return
	 * @throws Exception
	 */
	public List checkSelectjd() throws Exception {
		String sql = "select bm,mch from v_ic_jdb  ";
		List data = sys.query(sql, new Object[] {}, true);
		return data;
	}
	/**
	 * 社区下拉框选项下拉框选项
	 * @param lx
	 * @return
	 * @throws Exception
	 */
	public List getzlbkdate(String lx) throws Exception {
		String sql = "select bm,mch from v_ic_jdb  ";
		List data = sys.query(sql, new Object[] {lx}, true);
		return data;
	}
	/**
	 * 新增登记信息
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public String insertUnit(HashMap obj) throws Exception{	 
		String ss = sys.callDBFuncProce("ic_kgl.set_az75", "function", obj).toString();
		String[] str = ss.split("&");
		String result = str[0];
		return result;
	} 
	/**
	 * 新增登记信息
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public String insertUnit2(HashMap obj) throws Exception{	 
		String ss = sys.callDBFuncProce("ic_kgl.set_bkdj", "function", obj).toString();
		String[] str = ss.split("&");
		String result = str[0];
		return result;
	} 
}